import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class InterfaceCPU_Easy extends JFrame {

	private static final long serialVersionUID = 5520644475993052526L;
	// public static int Interface.input = 0;
	public static boolean proceed = true;

	public InterfaceCPU_Easy() {
		super("GUI Player 1");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JButton button1 = new JButton("Play Card 1");
		button1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					Interface.input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (Interface.input >= 1 && Interface.input <= 9
						&& x.length() != 0 && proceed == true
						&& Board.C12hide == false) {
					Card.playCard12();
					JOptionPane.showMessageDialog(rootPane,
							"Turn Over. CPU's turn...");
					dispose();
					Compare.main(null);
					AICPU_Easy.main(null, AICPU_Easy.AICPU_Easy);
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C12hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button2 = new JButton("Play Card 2");
		button2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					Interface.input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (Interface.input >= 1 && Interface.input <= 9
						&& x.length() != 0 && proceed == true
						&& Board.C11hide == false) {

					Card.playCard11();
					JOptionPane.showMessageDialog(rootPane,
							"Turn Over. CPU's turn...");
					dispose();
					Compare.main(null);
					AICPU_Easy.main(null, AICPU_Easy.AICPU_Easy);
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C11hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button3 = new JButton("Play Card 3");
		button3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					Interface.input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (Interface.input >= 1 && Interface.input <= 9
						&& x.length() != 0 && proceed == true
						&& Board.C10hide == false) {

					Card.playCard10();
					JOptionPane.showMessageDialog(rootPane,
							"Turn Over. CPU's turn...");
					dispose();
					Compare.main(null);
					AICPU_Easy.main(null, AICPU_Easy.AICPU_Easy);
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C10hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button4 = new JButton("Play Card 4");
		button4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					Interface.input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (Interface.input >= 1 && Interface.input <= 9
						&& x.length() != 0 && proceed == true
						&& Board.C9hide == false) {

					Card.playCard9();
					JOptionPane.showMessageDialog(rootPane,
							"Turn Over. CPU's turn...");
					dispose();
					Compare.main(null);
					AICPU_Easy.main(null, AICPU_Easy.AICPU_Easy);
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C9hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button5 = new JButton("Play Card 5");
		button5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					Interface.input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (Interface.input >= 1 && Interface.input <= 9
						&& x.length() != 0 && proceed == true
						&& Board.C8hide == false) {

					Card.playCard8();
					JOptionPane.showMessageDialog(rootPane,
							"Turn Over. CPU's turn...");
					dispose();
					Compare.main(null);
					AICPU_Easy.main(null, AICPU_Easy.AICPU_Easy);
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C8hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button6 = new JButton("Play Card 6");
		button6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					Interface.input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (Interface.input >= 1 && Interface.input <= 9
						&& x.length() != 0 && proceed == true
						&& Board.C7hide == false) {

					Card.playCard7();
					JOptionPane.showMessageDialog(rootPane,
							"Turn Over. CPU's turn...");
					dispose();
					Compare.main(null);
					AICPU_Easy.main(null, AICPU_Easy.AICPU_Easy);
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C7hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});

		JToolBar bar = new JToolBar(null, JToolBar.VERTICAL);
		JMenu label = new JMenu(Menu.PlayerCPU_Easy + "'s hand (Card 1-6)");
		label.setForeground(Color.BLUE);
		bar.add(label);
		bar.add(button1);
		bar.add(button2);
		bar.add(button3);
		bar.add(button4);
		bar.add(button5);
		bar.add(button6);
		bar.setBackground(Color.YELLOW);
		JPanel pane = new JPanel();
		pane.add("North", bar);
		setContentPane(pane);
	}

	public static void proceed() {
		if (Interface.input == 1 && Board.S1cap == false) {
			proceed = false;
		}
		if (Interface.input == 2 && Board.S2cap == false) {
			proceed = false;
		}
		if (Interface.input == 3 && Board.S3cap == false) {
			proceed = false;
		}
		if (Interface.input == 4 && Board.S4cap == false) {
			proceed = false;
		}
		if (Interface.input == 5 && Board.S5cap == false) {
			proceed = false;
		}
		if (Interface.input == 6 && Board.S6cap == false) {
			proceed = false;
		}
		if (Interface.input == 7 && Board.S7cap == false) {
			proceed = false;
		}
		if (Interface.input == 8 && Board.S8cap == false) {
			proceed = false;
		}
		if (Interface.input == 9 && Board.S9cap == false) {
			proceed = false;
		}
	}

	public static void main(String[] arguments) {
		InterfaceCPU_Easy frame = new InterfaceCPU_Easy();
		frame.setLocation(955, 505);
		frame.pack();
		frame.setVisible(true);
	}
}